<?php
defined('is_running') or die('Not an entry point...');

require("CalendarCommon.php");

class Calendar extends CalendarCommon {

	function CalendarInit() {
		global $addonFolderName,$page;
		$page->css_user[] = '/data/_addoncode/'.$addonFolderName.'/style.css';
	}

	function Calendar() {
		global $Monthevents, $cYear, $cMonth, $Year, $Month, $Day, $DaysInMonth, $FirstDayOfWeek, $EventFile, $EventID;

		CalendarCommon::Init();
		CalendarCommon::Defaults();

		// Date validator
		CalendarCommon::EventDateValidator();
		CalendarCommon::LoadEvents();

		$cmd = common::GetCommand();
		// Admin functions
		if ( common::LoggedIn() ) {
			switch($cmd) {
				case 'event_edit':
					CalendarCommon::EditEvent(); // Edit Event Form
					return;
				case 'event_editsave':
					CalendarCommon::SaveEditEvent();
					break;
				case 'event_delete':
					CalendarCommon::DeleteEvent(); // Delete Event Ajax Form
					return;
				case 'event_execdelete':
					if ( CalendarCommon::SaveDeleteEvent() ) { $Day = ''; }
					break;
				case 'event_new':
					CalendarCommon::NewEvent(); // New Event Form
					return;
				case 'event_newsave':
					CalendarCommon::SaveNewEvent();
					break;
			}
		}
		// User functions
		if ( $cmd == 'event_view' && !empty($Day) ) {
			CalendarCommon::ViewEvent();
			return;
		}
		if ( !empty($Year) ) {
			CalendarCommon::ViewMonth();
			return;
		}
		echo 'Hiba lépett fel, ha többször előfordul kérjük lépjen kapcsolatba a rendszergazdával.'; // *FIXME*
		return;
	}

	function CalendarGadget() {
		global $Monthevents, $cYear, $cMonth, $Year, $Month, $Day, $DaysInMonth, $FirstDayOfWeek, $EventFile, $EventID;

		CalendarCommon::Init();
		CalendarCommon::Defaults();

		CalendarCommon::EventDateValidator();
		CalendarCommon::LoadEvents();

		$cmd = common::GetCommand();
		switch($cmd) {
			case 'event_Month':
			case 'event_now':
				break;
		}

		$myCalendar = new MonthCalendar;
		$myCalendar->ShowCalendar();
	}
}
